package com.ruoyi.project.business.controlcenter;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.controlcenter.iot.manager.IotManager;
import com.ruoyi.project.business.controlcenter.request.IotRequest;
import com.ruoyi.project.business.gpiobiz.request.ListControlGpioBizRequest;
import com.ruoyi.project.business.gpiobiz.response.ControlGpioBizResponse;
import com.ruoyi.project.business.gpiobiz.service.IControlGpioBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备引脚业务Controller
 * 
 * @author ${author}
 * @date 2024-07-25
 */
@Slf4j
@RestController
@RequestMapping("/business/house")
public class HouseControlController extends BaseController {
    @Autowired
    private IotManager iotManager;
    @Autowired
    private IControlGpioBizService controlGpioBizService;

    /**
     * 查询家庭已支持远程控制的线路
     */
    @GetMapping("/list")
    public TableDataInfo list(ListControlGpioBizRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<ControlGpioBizResponse> list = controlGpioBizService.selectListWithMac(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 开指定的 gipo
     */
    /**
     * turn
     * @param req
     * @return
     */
    @PostMapping("/turn")
    public AjaxResult turn(@RequestBody IotRequest req) {
        iotManager.operateIndex(req.getIndex(), req.getMac(), req.getOnOff());
        return AjaxResult.success("ok");
    }
}
